<?php
namespace App\Helpers;

use Illuminate\Support\Facades\URL;
use Symfony\Component\HttpFoundation\Response as FoundationResponse;
use Response;

/**
 * 接口响应
 * @package App\Helpers
 */
trait ApiResponse
{
    /**
     * 返回状态码
     * @var int
     */
    protected $resStatusCode = FoundationResponse::HTTP_OK;
    /**
     * @return mixed
     */
    public function getStatusCode()
    {
        return $this->resStatusCode;
    }

    /**
     * @param $statusCode
     * @return $this
     */
    public function setStatusCode($statusCode)
    {
        $this->resStatusCode = $statusCode;
        return $this;
    }

    /**
     * @param int $code
     * @param string $message
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     * 接口统一返回信息函数
     */
    public function responseJson($code = 0, $data = [], $message = '')
    {
        $responseData = [
            'code' => $code,
            'message' => $message
        ];
        $responseData['data'] = $data;

        return response()->json($responseData);
    }
}